package com.example.swaggerDemo.service;


import com.example.swaggerDemo.Dao.articeByUseridDao;
import com.example.swaggerDemo.entity.articeByUseridEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestParam;

import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.List;
@Repository
public class articeByUseridService implements articeByUseridDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<articeByUseridEntity> findAll(@RequestParam("pageindex") int pagindex,
                                              @RequestParam("pagesize") int pagesize,
                                              @RequestParam("id") String id,
                                              @RequestParam("username") String username
    ) throws SQLException {
String sql="";
if (username!=""&&username!=null)
{
    sql = "select * from articebyuserid"+" where username="+"'"+username+"'"+ " AND upid='"+id+"'" + " LIMIT "+ pagindex +","+pagesize;
}
else {
     sql = "select * from articebyuserid"+ " where upid= '"+id+"'" + " LIMIT "+ pagindex +","+pagesize;
}
        List<articeByUseridEntity> dto= jdbcTemplate.query(sql, new BeanPropertyRowMapper(articeByUseridEntity.class));
        return dto;
    }
}
